package edu.xkd.hormany_test3.hormany03_03.slice;

import edu.xkd.hormany_test3.hormany03_03.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;

public class MainAbilitySlice extends AbilitySlice {
    boolean flag=true;//是否为第一次点击 true 为是第一次
    int num=0;
    long startTime=0;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Button button1 = (Button)findComponentById(ResourceTable.Id_but1);
        Text text1 = (Text) findComponentById(ResourceTable.Id_text1);
        button1.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                num++;
                if(flag){
                    flag=false;
                    text1.setText(num+"");
                    button1.setText("疯狂点我");
                    startTime=System.currentTimeMillis();
                }else {
                    long endTime=System.currentTimeMillis();
                    if(endTime-startTime<=10000){
                        text1.setText(num+"");
                    }else{
                        text1.setText("恭喜您：最终点击"+num+"次");
                        button1.setTextColor(Color.RED);
                        button1.setText("结束");
                        button1.setClickable(false);
                    }
                }
                //如果是第一次点击按钮
                //文本框显示10内点击次数
                //按钮显示疯狂点击

                //非第一次点击
                //在10秒之内
                   //文本框显示当前点击次数
                //不在10秒之内
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
